package com.szc.demo01.controller;

import com.szc.demo01.controller.base.BaseController;
import com.szc.demo01.pojo.User;
import com.szc.demo01.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 登录控制器
 * @Author: ShiZhiCheng
 * @Date: 2021/01/12 17:51:36
 */
@Controller
public class LoginController extends BaseController {

    @Resource
    UserService userService;

    /**
     * 登录操作
     * @param user 用户名
     */
    @PostMapping("/login")
    public String toMain(User user, HttpSession httpSession, Model model){

        User cUser = userService.getByUsernameAndPasswordUser(user);
        if (cUser != null){
            httpSession.setAttribute("user",cUser);
            httpSession.setAttribute("has1",userIdHasPerm(1));
            httpSession.setAttribute("has2",userIdHasPerm(2));
            httpSession.setAttribute("has3",userIdHasPerm(3));
            httpSession.setAttribute("has4",userIdHasPerm(4));
            httpSession.setAttribute("has5",userIdHasPerm(5));
            httpSession.setAttribute("has6",userIdHasPerm(6));
            return "redirect:/main.html";
        }else {
            model.addAttribute("usernameLogin",user.getUsername());
            model.addAttribute("msg","账户或密码不存在");
            return "login";
        }
    }





}
